import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.Timer;

public class Pathfinder {
	
	
	public static void main(String[] args) throws InterruptedException {
		//args = new String[]{"battleground.map", "0", "0", "55", "56", "DFSSearcher", "demo", "1000000"};
		
		int [] maxDimensions = new int[2];
		char[][] mapa = ParseMap(args[0],maxDimensions);
		int x_inicial = Integer.parseInt(args[1]); // posicion inicial
		int y_inicial = Integer.parseInt(args[2]);
		int x_meta = Integer.parseInt(args[3]);    // posicion final
		int y_meta = Integer.parseInt(args[4]);
		boolean demo_mode = args[6].equals("demo");
		double time_limit = Double.parseDouble(args[7]);  // tiempo limite

		
		Controller control = new Controller(args[5], mapa, x_inicial,
				y_inicial, x_meta, y_meta,maxDimensions[0],maxDimensions[1],demo_mode,time_limit);

		// Iniciamos el ciclo de búsqueda.

		
		if (demo_mode) {
//			Timer t = new Timer();
//			t.scheduleAtFixedRate(control, 0, 100);
			while (true) {
				control.run();
				Thread.sleep(150);
			}
			
		} else {
			while (control.Seguir()) {
				control.run();
			}
		}
		
	}

	private static char[][] ParseMap(String path,int[] maxDimensions) {
		Scanner sc = null;
		try {
			sc = new Scanner(new File(path));
		} catch (FileNotFoundException e) {
			System.out.println("Archivo Incorrecto - Mapa no encontrado");
			e.printStackTrace();
			System.exit(0);
		}

		sc.next(); // type
		sc.next(); // value
		sc.next(); // height
		int height = sc.nextInt();
		sc.next(); // width
		int width = sc.nextInt();
		sc.next(); // map

		// Iniciamos el mapa
		char[][] map = new char[height][width];
		maxDimensions[0] = height;
		maxDimensions[1] = width;
		// Saltamos los numeros
//		for (int i = 0; i < height; i++)
//			sc.next();

		// Leemos las letras
		for (int i = 0; i < height; i++) {
			String fila = sc.next();
			for (int j = 0; j < width; j++) {
				map[i][j] = fila.charAt(j);
			}

		}
		return map;
	}

}
